Ce script créer un fichier NFO pour les dossiers contenant des fichier MP3 ou FLAC. Il a été adapté depuis un script bugué dégoté sur le forum, il fonctionne mais il se pourrait qu'il y ait encore des bug, il n'a pas été complètement débogué
######################################################################
#
# musicNFO v0.1b 2016-12-31 altg
#
######################################################################
usage() {
echo "usage: $0 [-m | -f] [title column witdh] [directory path] "
exit 1
}
# Files format
ext=flac
# if "-m" look for MP3 files
[ "a$1" = a-m ] && shift && ext=mp3
# if "-f" look for FLAC files (default)
[ "a$1" = a-f ] && shift && ext=flac
# Title column witdh
col=40
# if col=0, display titles entirely
[ "$1" -ge 0 ] 2>/dev/null && col=$1 && shift
# Directory Path
[ -d "$1" ] && path="$1" && totalsize=`du -sh "$1" | awk '{print $1}'` && set "$1"/*.$ext
# Extract Mediainfo from files
[ -f "$1" ] || usage
file=/tmp/musicnfo$$
mediainfo "$1" | sort -u > $file
artist=`awk -F: '$1~/^Performer/ { print $2 }' $file` && artist=${artist:1}
album=`awk -F: '$1~/^Album/ { print $2 }' $file` && album=${album:1}
genre=`awk -F: '$1~/^Genre/ { print $2 }' $file`
year=`awk -F: '$1~/^Recorded/ { print $2 }' $file`
ripper=`awk -F: '$1~/^Writing/ { print $2 }' $file`
format=`awk -F: '$1~/^Format / { print $2 }' $file`
fprof=`awk -F: '$1~/^Format p/ { print $2 }' $file`
fvers=`awk -F: '$1~/^Format v/ { print $2 }' $file`
rate=`awk -F: '$1~/^Sampling/ { print $2 }' $file`
channels=`awk -F: '$1~/^Channel/ { print $2 }' $file`
title="$artist - $album" && titlelen=${#title}
ofile="$title.nfo"
output="$path/$ofile"
let seplen="$col+52"
for ((i=0; i<$seplen; i++)); do sep="$sep-";done
let titlepos="$seplen/2+$titlelen/2-1"
## PRINT
if [ "$col" -ne 0 ] ; then
printf "%s\n %*s\n%s\n\n" "$sep" "$titlepos" "$title" "$sep" > "$output"
printf "%-20s: %s\n" "Artist" " $artist" >> "$output"
printf "%-20s: %s\n" "Album" " $album" >> "$output"
printf "%-20s: %s\n" "Genre" "$genre" >> "$output"
printf "%-20s: %s\n" "Year" "$year" >> "$output"
printf "%-20s: " Ripper >> "$output" ; echo "$ripper" >> "$output"
printf "%-20s: %s %s %s\n" Format "$format" "$fprof" "$fvers" >> "$output"
printf "\n%s\n" "$sep" >> "$output"
case $col in
1) fmt='%2s|%-40s|%10s |%10s |%10s |%10s |\n%s\n' ;;
*) fmt='%2s|%-'$col's|%10s |%10s |%10s |%10s |\n%s\n';;
esac
printf "$fmt" " #" " Title" " Duration" " Size" " Bitrate" " Mode" $sep >> "$output"
fi
typeset -i n
n=1
while [ a"$1" != a ]
do
[ -f "$1" ] || usage
file=/tmp/musicnfo$$
mediainfo "$1" | sort -u > $file
duration="`awk -F: '$1~/^Duration/ { print $2 }' $file | head -1`"
size="`awk -F: '$1~/^File/ { print $2 }' $file`"
bitrate="`awk -F: '$1~/^Overall bit rate[ ]*$/ { print $2 }' $file`"
mode="`awk -F: '$1~/^Overall bit rate mode/ { print $2 }' $file`"
case $col in
1)track="`awk -F: '$1~/^Track name / { print $2 }' $file`";;
0)track="`awk -F: '$1~/^Track name / { print $2 }' $file`";;
*)track="`awk -F: '$1~/^Track name / { print $2 }' $file | cut -c1-$col`";;
esac
[ -z "$track" ] && track="$1"
index="`awk -F: '$1~/Position / { print $2 }' $file`"
[ a"$index"=a ] && index=$n
n=$n+1
case $col in
1)fmt='%2s|%-40s|%10s |%10s |%10s |%10s |\n';;
0)fmt='%2s|%s\n';;
*)fmt='%2s|%-'$col's|%10s |%10s |%10s |%10s |\n';;
esac
if [ "$col" -ne 0 ] ; then
printf "$fmt" "$index" "$track" "$duration" "$size" "$bitrate" "$mode" >> "$output"
else
printf "$fmt" "$index" "$track" >> "$output"
fi
shift
done
if [ $col -gt 0 ]
then
printf "%s\n\n" $sep >> "$output"
echo "Total Size...........:" $totalsize"B." >> "$output"
echo "NFO generated on.....:" `date +"%D %T"` >> "$output"
rm $file
fi
echo "$ofile written successfully"
echo "in folder $path ..."
echo "ENJOY !"
exit 0
##############################################################